# -*- coding: utf-8 -*-

import cgi

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db

import models.milestonePlan as MPm
import models.city as cm

def view( mp ):
    response = "<h2>View milestone plan no. %d</h2><table %s>"% (mp.ident, 'class="gt"' if mp.archival else '')
    response += '<tr><td><i>Time</i></td><td><i>City</i></td><td><i>Status</i></td></tr>\n'
	
    for tuple in mp.plan:
        decoded = MPm.MPModel.tupleDecode(tuple)
        query = cm.CityModel.all()
        city = query.filter( 'code =', str(decoded[1]) ).get()
        response += '<tr><td>%s</td><td>%s</td><td>%s</td></tr>' % (decoded[0], city.linkTo(action='show1', text=city.code), decoded[2])

    response += '''</table>
    Current delay: <b>%d hours</b>''' % (mp.currentDelay)
    

    return response
